import { createApp } from 'vue';
import App from './App.vue';
import routes from './router';
import { createRouter, createWebHistory } from 'vue-router';
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
// 引入pina
import { createPinia } from 'pinia';
const pinia=createPinia()
let app;

function render(props = {}) {
  console.log(props,'props-----------');
  const { container, routerBase = '/app-vue' } = props;
  const router = createRouter({
    routes,
    history: createWebHistory(routerBase)
  });
  app = createApp(App);
  app.config.globalProperties.parentActions = props.parentActions
  app.use(router).use(pinia).mount(container || '#app');
}

if (qiankunWindow.__POWERED_BY_QIANKUN__) {
  renderWithQiankun({
    bootstrap() {},
    mount(props) {
      props.onGlobalStateChange = (state, prev) => {
        console.log(state, prev,'***********************');
      };

      render(props);
    },
    unmount() {
      app.unmount();
      app = null;
    }
  });
}

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();

  console.log('独立运行');
}
